package com.alks.common.data.enums.system;

import com.alks.common.config.interceptor.CompanyConstants;
import com.alks.common.data.dto.SysUserTokenDTO;
import com.alks.common.utils.beanutils.BeanUtil;
import com.alks.common.utils.stringUtils.SpringUtils;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import org.apache.naming.factory.BeanFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;

/**
 * @author MS
 * @since 2024/12/6上午9:55
 */
@Getter
@RequiredArgsConstructor
public enum LoginPermEnum {

    /**
     * PDA 用户
     */
    PDA("PDA","PDA001","PDA001_token","BF","PDA01");
//    LTF("林添发","LTF","LTF_token","BF","ZQ01");

    private String userName;
    private String loginName;
    private String token;
    private String companyId;
    private String posId;

    LoginPermEnum(String userName,String loginName,String token,String companyId,String posId){
        this.userName = userName;
        this.loginName = loginName;
        this.token = token;
        this.companyId = companyId;
        this.posId = posId;
    }

    /**
     * 快速校验忽略名单
     * @param loginName 待校验名单
     * @return 检验结果
     */
    public static boolean permExist(String loginName) {
        for (LoginPermEnum perm : LoginPermEnum.values()) {
            if (perm.getLoginName().equals(loginName)) {
                return true;
            }
        }
        return false;
    }


    /**
     * 快速校验忽略名单
     * @param token 待校验名单
     * @return 检验结果
     */
    public static boolean tokenExist(String token) {
        for (LoginPermEnum perm : LoginPermEnum.values()) {
            if (perm.getToken().equals(token)) {
                return true;
            }
        }
        return false;
    }

    public static SysUserTokenDTO getUserByToken(String token) {
        for (LoginPermEnum perm : LoginPermEnum.values()) {
            if (perm.getToken().equals(token)) {
                SysUserTokenDTO tokenDTO = new SysUserTokenDTO();
                CompanyConstants constants = SpringUtils.getBean(CompanyConstants.class);
                switch (constants.getPort()){
                    case "7700":
                        tokenDTO.setCompanyId("DF");
                        break;
                    case "7100":
                        tokenDTO.setCompanyId("HF");
                        break;
                    default:
                        tokenDTO.setCompanyId("BF");
                        break;
                }
                tokenDTO.setUserName(perm.getUserName());
                tokenDTO.setLoginName(perm.getLoginName());
                return tokenDTO;
            }
        }
        return new SysUserTokenDTO();
    }
}
